﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Db.Paging;
using System.Data.Common;

namespace Db.Paging
{
    internal class SQLitePager : IPager
    {

        #region IPager 成员

        public System.Data.DataTable Paging(string sql, int currentPageIndex, int pageSize,DbHelper hp)
        {
            sql = sql + " Limit " + pageSize + " Offset " + ((currentPageIndex - 1) * pageSize);


            return hp.ExecuteDataTable( hp.GetSqlStringCommond(sql) );
        }

        public int CountPaging(string sql, DbHelper hp)
        {
            sql = "SELECT count(1) from ( " + sql + ")";
            object obj =hp.ExecuteScalar(hp.GetSqlStringCommond(sql));

            return Convert.ToInt32(obj);
        }

        #endregion
    }
}
